package com.zhentao.login.utils;

import com.zhentao.nlz.project.login.TUser;

/**
 * @Author: 天山一剑卓不凡
 */
//线程和用户绑定
public class AuthContextUtil {
    //threadlocal 线程的私有变量的绑定，私有变量是归属于某一个线程的，线程和线程之前的私有变量是完全隔离的
    private static final ThreadLocal<TUser> threadLocal = new ThreadLocal<>();
    //完成绑定
    public static void setUser(TUser user){
        threadLocal.set(user);
    }
    //获取绑定的变量
    public static TUser getUser(){
        return threadLocal.get();
    }
    //移除绑定
    public static void remove(){
        threadLocal.remove();
    }

}
